#' @title Are values in two vectors/columns the same.
#'
#' @description Check per index/row whether values in two vectors/columns are the same.
#'
#' @author Pieter Overdevest
#'
#' @param x1 Column or vector 1.
#' @param x2 Column or vector 2.
#'
#' @return Column containing TRUE or FALSE.
#'
#' @details -
#'
#' @examples
#' f_is_same(
#' x1 = c(1,2,3,4,5,NA),
#' x2 = c(1,2,3,4,NA,NA)
#' )
#'
#' @export
#'
#################################################################################
# FUNCTION.
#################################################################################
f_is_same <- function(
x1, x2
) {
##############################################################################
# TEST ONLY!!
##############################################################################
##############################################################################
# Initialize // Error checking
##############################################################################
##############################################################################
# Main
##############################################################################
v.output <- ifelse(
!is.na(x1) & !is.na(x2),
{x1 == x2},
ifelse(
is.na(x1) & is.na(x2),
TRUE,
FALSE
)
)
##############################################################################
# Return
##############################################################################
return(v.output)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.